import { Tooltip } from 'antd';
import { TooltipProps } from 'antd/es/tooltip';
import React, { createContext, useContext, useState } from 'react';

export const AdvTooltipContext = createContext<Record<string, any>>({});
export const useAdvTooltip = () => useContext(AdvTooltipContext);

export const AdvTooltip = (props: TooltipProps) => {
  const [visible, setVisible] = useState(false);
  const closeTip = () => {
    if (visible) {
      setVisible(false);
    }
  };
  return (
    <AdvTooltipContext.Provider value={{ closeTip }}>
      <Tooltip {...props} visible={visible} onVisibleChange={setVisible} />
    </AdvTooltipContext.Provider>
  );
};

export default AdvTooltip;
